﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using System.Reactive.Linq;
using ReactiveUI.Xaml;

namespace InstantSpine.WPFPlayGround
{
    public class EinTestDing
    {
        public int Age { get; set; }
        public string Name { get; set; }
    }
    
    public class ExpObj
    {
        [ExpandableObject]        
        public EinTestDing Prop1 { get; set; }

        [ExpandableObject]
        public EinTestDing Prop2 { get; set; }

        public ExpObj() {
            this.Prop1 = new EinTestDing();
            this.Prop2 = new EinTestDing();
        }
    }

    public class TestDinger
    {
        public ObservableCollection<EinTestDing> Dinger { get; set; }
        public TestDinger() {
            this.Dinger = new ObservableCollection<EinTestDing> { 
                new EinTestDing { Age = 3, Name = "Bubi" }, 
                new EinTestDing { Age = 100, Name = "Heini" } 
            };
        }
    }

    public class Zeug
    {
        public ObservableCollection<int> ValidNums { get; set; }

        public Zeug() {
            this.ValidNums = new ObservableCollection<int> { 1, 2, 3, 4, 5, 6, 7 };
        }
    }

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        ObservableCollection<EinTestDing> dinger;

        public MainWindow() {
            InitializeComponent();

            // programatic binding
            var d1 = new EinTestDing { Name = "Test1", Age = 1 };
            var d2 = new EinTestDing { Name = "Test2", Age = 2 };
            dinger = new ObservableCollection<EinTestDing> { d1, d2 };
            var binding = new Binding { Source = dinger };
            diebox.SetBinding(ComboBox.ItemsSourceProperty, binding);
            
            // ReactiveUI
            var mouseUp = Observable.Merge(
                // can execute == false when mouse button down
                Observable.FromEventPattern<MouseButtonEventArgs>(this, "MouseDown").Select(_ => false),
                Observable.FromEventPattern<MouseButtonEventArgs>(this, "MouseUp").Select(_ => true))
                .StartWith(true);

            var cmd = new ReactiveCommand(mouseUp);
            cmd.Subscribe(x => MessageBox.Show(x.ToString()));


        }
    }
}
